// run: time $exec < input
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <utility>

struct people
{
	int value;
	std::string name;
	int index;
};

bool operator<(people const & a, people const & b)
{
	return (a.value < b.value || (a.value == b.value && a.index > b.index));
}

struct open
{
	int time; // after t-th people come
	int p; // let p in
};

bool operator<(open const & a, open const & b)
{
	return a.time < b.time;
}

int const maxn = 150007;
int const maxq = 107;

int n, m, q;

std::vector<people> data(maxn);
std::vector<open> open_door;
std::vector<int> query;
std::vector<std::string> ans(maxq);

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> n >> m >> q;
		for (int i = 0; i < n; i++) {
			std::cin >> data[i].name >> data[i].value;
			data[i].index = i;
		}

		open_door.clear();
		open_door.resize(m);
		for (int i = 0; i < m; i++)
			std::cin >> open_door[i].time >> open_door[i].p;

		query.clear();
		query.resize(q);
		for (int i = 0; i < q; i++)
			std::cin >> query[i];
		std::sort(query.begin(), query.end());

		std::sort(open_door.begin(), open_door.end());
		open tmp; tmp.time = n; tmp.p = n;
		open_door.push_back(tmp);
		m++;

		std::priority_queue<people> pq;

		int openi = 0, qi = 0, come_in = 0;
		for (int i = 1; i <= n; i++) {
			pq.push(data[i-1]);
			while (openi < m && open_door[openi].time == i) {
				for (int tot = 0; tot < open_door[openi].p && !pq.empty(); tot++) {
					int tmp = pq.top().index;
					pq.pop();
					come_in++;
					if (come_in == query[qi]) {
						ans[qi] = data[tmp].name;
						qi++;
					}
				}
				openi++;
			}
		}

		if (q) std::cout << ans[0];
		for (int i = 1; i < q; i++)
			std::cout << ' ' << ans[i];
		std::cout << '\n';
	}
}

